﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ManageSystem
{
    public partial class RegeistUser : Form
    {
        public RegeistUser()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Equals(""))
            {
                MessageBox.Show("请输入姓名!");
                textBox1.Focus();
                return;
            }
            else if (textBox2.Text.Equals(""))
            {
                MessageBox.Show("请输入年龄！");
                textBox2.Focus();
                return;
            }
            else if (this.textBox2.Text != "")
            {
                if (this.IsNumberic(this.textBox2.Text) == false)

                {
                    MessageBox.Show("年龄请输入数字！");
                    this.textBox2.Focus();
                    return;
                }
            }
            else if (textBox3.Text.Equals(""))
            {
                MessageBox.Show("请输入班级！");
                textBox2.Focus();
                return;
            }
            else if (!textBox5.Text.Equals(textBox4.Text))
            {
                MessageBox.Show("两次密码输入不一致!");
                return;
            }

            string stuSex = "";
            if (radioButton1.Checked == true)
                stuSex = "男";
            else if (radioButton2.Checked == true)
                stuSex = "女";

            string commend = "insert into UserInfo (UserName,UserAge,UserSex,UserClass,UserPwd) values(N'" + textBox1.Text + "'," + textBox2.Text + ",N'" + stuSex + "',N'" + textBox3.Text + "',N'" + textBox4.Text + "')";
            if (Utils.ExecuteNoQuery(commend) != -1)
            {
                MessageBox.Show("创建成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("创建失败");
            }
        }

        private bool IsNumberic(string oText)
        {
            try
            {
                int var1 = Convert.ToInt32(oText);
                return true;
            }
            catch
            {
                return false;
            }
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
